package controllers;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import models.Hobby;
import models.User;
/**
 *
 * @author Rasztemberg
 */

@Named(value = "userProfileBean")
@RequestScoped
public class UserProfile implements Serializable{

    private User user;
    
    private Integer selectedItem;
    private Map<String, Integer> userHobbies;
    
    
    public UserProfile(){
        user = new User();
        userHobbies = new LinkedHashMap<String, Integer>();        
    }
    
   // HELPER FUNCTIONS ------------------------------------------------------------
   
   
    
    // ACTIONS -------------------------------------------------------------------
    public User selectUserProfileInfo(int id) {
       if(user.getId() != null){
           return user;
       }
       user = User.selectById(id);
       return user;
    }
    
    public List<Hobby> selectUserHobbies(int id){
        return Hobby.selectUserHobbies(id);
    }
    
    public Map<String, Integer> selectAllHobbies(){
        for(Hobby h: Hobby.selectAllHobbies()){
            userHobbies.put( h.getName(), h.getId());
        }
        return userHobbies;
    }
    
    public void addNewHobby(int user_id){
      Hobby.addUserHobby(user_id, selectedItem);
    }
   
    
    public void editProfile(){        
        user.update();
    }
    
    
    // GETTERS -------------------------------------------------------------------
    public User getUser() {
        return user;
    }
    
    public Integer getSelectedItem(){
        return selectedItem;
    }

   // SETTERS ------------------------------------------------------------------
    public void setUser(User user) {
        this.user = user;
    } 
    
     public void setSelectedItem(Integer intek) {
        this.selectedItem = intek;
    } 
}
